package com.frxuexi.document

import com.frxuexi.lib_base.ApiResp
import com.frxuexi.lib_base.BaseViewModel
import com.frxuexi.lib_base.RequestType
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class DocViewModel @Inject constructor(private val docRepo: DocRepo):BaseViewModel<DocIntent>() {
    override fun handleIntent(it: DocIntent) {
        when(it){
            is DocIntent.getDocs->httpRequest(docRepo.getDocs(it.map) as Flow<ApiResp<Any>>)
            is DocIntent.deleteDoc->httpRequest(docRepo.deleteDoc(it.map),RequestType.DELETE)
            is DocIntent.scanFile->
                scanFile(it.file)
            is DocIntent.upload->
                httpRequest(docRepo.upload(it.name,it.path))
        }

    }
}